﻿using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;//请先添加引用

namespace OracleDAL.Topo
{
    /// <summary>
    /// 
    /// </summary>
   public  class SERVICECONNECTION
    {
       /// <summary>
       /// 
       /// </summary>
   public SERVICECONNECTION()
		{}
		#region  成员方法

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string SERVICECONNECTIONID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from SERVICECONNECTIONLIST");
			strSql.Append(" where SERVICECONNECTIONID=:SERVICECONNECTIONID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SERVICECONNECTIONID", OracleType.VarChar,50)};
			parameters[0].Value = SERVICECONNECTIONID;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.Topo.SERVICECONNECTION model)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SERVICECONNECTIONLIST(");
            strSql.Append("SERVICECONNECTIONID,SERVICECONNECTIONNAME,SERVICECONNECTIONTYPE,BACKGROUNDIMAGE,SHORTHAND)");
            strSql.Append(" values (");
            strSql.Append(":SERVICECONNECTIONID,:SERVICECONNECTIONNAME,:SERVICECONNECTIONTYPE,:BACKGROUNDIMAGE,:SHORTHAND)");
            OracleParameter[] parameters = {
					new OracleParameter(":SERVICECONNECTIONID", OracleType.VarChar,25),
					new OracleParameter(":SERVICECONNECTIONNAME", OracleType.VarChar,200),
					new OracleParameter(":SERVICECONNECTIONTYPE", OracleType.VarChar,50),
					new OracleParameter(":BACKGROUNDIMAGE", OracleType.VarChar,100),
					new OracleParameter(":SHORTHAND", OracleType.VarChar,200)};
            parameters[0].Value = model.SERVICECONNECTIONID;
            parameters[1].Value = model.SERVICECONNECTIONNAME;
            parameters[2].Value = model.SERVICECONNECTIONTYPE;
            parameters[3].Value = model.BACKGROUNDIMAGE;
            parameters[4].Value = model.SHORTHAND;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Model.Topo.SERVICECONNECTION model)
		{
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update SERVICECONNECTIONLIST set ");
            strSql.Append("SERVICECONNECTIONNAME=:SERVICECONNECTIONNAME,");
            strSql.Append("SERVICECONNECTIONTYPE=:SERVICECONNECTIONTYPE,");
            strSql.Append("BACKGROUNDIMAGE=:BACKGROUNDIMAGE,");
            strSql.Append("SHORTHAND=:SHORTHAND");
            strSql.Append(" where SERVICECONNECTIONID=:SERVICECONNECTIONID ");
            OracleParameter[] parameters = {
					new OracleParameter(":SERVICECONNECTIONID", OracleType.VarChar,25),
					new OracleParameter(":SERVICECONNECTIONNAME", OracleType.VarChar,200),
					new OracleParameter(":SERVICECONNECTIONTYPE", OracleType.VarChar,50),
					new OracleParameter(":BACKGROUNDIMAGE", OracleType.VarChar,100),
					new OracleParameter(":SHORTHAND", OracleType.VarChar,200)};
            parameters[0].Value = model.SERVICECONNECTIONID;
            parameters[1].Value = model.SERVICECONNECTIONNAME;
            parameters[2].Value = model.SERVICECONNECTIONTYPE;
            parameters[3].Value = model.BACKGROUNDIMAGE;
            parameters[4].Value = model.SHORTHAND;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string SERVICECONNECTIONID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from SERVICECONNECTIONLIST ");
			strSql.Append(" where SERVICECONNECTIONID=:SERVICECONNECTIONID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SERVICECONNECTIONID", OracleType.VarChar,50)};
			parameters[0].Value = SERVICECONNECTIONID;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.Topo.SERVICECONNECTION GetModel(string SERVICECONNECTIONID)
		{

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SERVICECONNECTIONID,SERVICECONNECTIONNAME,SERVICECONNECTIONTYPE,BACKGROUNDIMAGE,SHORTHAND from SERVICECONNECTIONLIST ");
            strSql.Append(" where SERVICECONNECTIONID=:SERVICECONNECTIONID ");
            OracleParameter[] parameters = {
					new OracleParameter(":SERVICECONNECTIONID", OracleType.VarChar,50)};
            parameters[0].Value = SERVICECONNECTIONID;

			Model.Topo.SERVICECONNECTION model=new Model.Topo.SERVICECONNECTION();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.SERVICECONNECTIONID=ds.Tables[0].Rows[0]["SERVICECONNECTIONID"].ToString();
				model.SERVICECONNECTIONNAME=ds.Tables[0].Rows[0]["SERVICECONNECTIONNAME"].ToString();
				model.SERVICECONNECTIONTYPE=ds.Tables[0].Rows[0]["SERVICECONNECTIONTYPE"].ToString();
				model.BACKGROUNDIMAGE=ds.Tables[0].Rows[0]["BACKGROUNDIMAGE"].ToString();
                model.SHORTHAND = ds.Tables[0].Rows[0]["SHORTHAND"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select SERVICECONNECTIONID,SERVICECONNECTIONNAME,SERVICECONNECTIONTYPE,BACKGROUNDIMAGE,SHORTHAND ");
            strSql.Append(" FROM SERVICECONNECTIONLIST ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return OracleHelper.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "SERVICECONNECTIONLIST";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}

